package cn.echoedu.command;

import java.util.ArrayList;
import java.util.List;

import cn.echoedu.command.base.Command;
import cn.echoedu.command.base.ExecuteParam;
import cn.echoedu.command.base.FailureParam;
import cn.echoedu.command.base.SuccessParam;
import cn.echoedu.entity.ClassNotify;
import cn.echoedu.entity.ClassNotifyImage;
import cn.echoedu.entity.Image;
import cn.echoedu.util.DateUtil;

import com.google.gson.Gson;

public class ClassNotifyDetail extends BaseCommand {

	public void executeSuccess(SuccessParam successparam) {
		// TODO Auto-generated method stub
		List<ClassNotifyImage> classnotifyimagelist =
				(List<ClassNotifyImage>)successparam.getParam();
		if(classnotifyimagelist==null||classnotifyimagelist.size()<=0)
		{
			return;
		}
		ClassNotifyImage classnotifyimage = classnotifyimagelist.get(0);
		ClassNotify classnotify = classnotifyimage.getClassnotify();
		ClassNotifyListDetail classnotifylistdetail = new ClassNotifyListDetail();
		classnotifylistdetail.setCode(successparam.getCode());
		classnotifylistdetail.setMsg("query classnotify detail success");
		classnotifylistdetail.setClassnotifyid(classnotify.getClassnotify());
		classnotifylistdetail.setTheme(classnotify.getTitle());
		classnotifylistdetail.setPlace(classnotify.getContent());
		classnotifylistdetail.setContent(classnotify.getContent());
		classnotifylistdetail.setFilepath(classnotify.getFilepath());
		if(classnotify.getStarttime()!=null){
			classnotifylistdetail.setStarttime(DateUtil.dateToString(classnotify.getStarttime()));
		}
		if(classnotify.getEndtime()!=null){
			classnotifylistdetail.setEndtime(DateUtil.dateToString(classnotify.getEndtime()));
		}
		if(classnotify.getRemindertime()!=null){
			classnotifylistdetail.setAttion_time(DateUtil.dateToString(classnotify.getRemindertime()));
		}
		classnotifylistdetail.setHitcount(classnotify.getHitcount());
		if(classnotify.getPublishtime()!=null){
			classnotifylistdetail.setTime(DateUtil.dateToDetailString(classnotify.getPublishtime()));
		}
		classnotifylistdetail.setUser_number(classnotify.getStudent().getStudentnumber());
		classnotifylistdetail.setLikenum(classnotify.getLikenum());
		classnotifylistdetail.setDislikenum(classnotify.getDislikenum());
		List<Pic> piclist = new ArrayList<Pic>();
		for(int index=0,len=classnotifyimagelist.size();index<len;index++){
			ClassNotifyImage classnotifyimagetemp = classnotifyimagelist.get(index);
			if(classnotifyimagetemp!=null){
				Image image = classnotifyimagetemp.getImageid();
				if(image!=null&&image.getImagesrc()!=null){
					Pic pic = new Pic();
					pic.setPic_url(image.getImagesrc());
					piclist.add(pic);
				}
			}
		}
		classnotifylistdetail.setPic_url_list(piclist);
		String resultjson = new Gson().toJson(classnotifylistdetail);
		send(resultjson,successparam.getResponse());
	}
	public void executeFailure(FailureParam failureparam) {
		// TODO Auto-generated method stub

	}

	public void execute(ExecuteParam executeparam) {
		// TODO Auto-generated method stub

	}
	private class ClassNotifyListDetail{
		private int code = 112;
		private String msg = "";
		private int classnotifyid;
		private String theme;
		private String place;
		private String content;
		private String filepath;
		private String starttime;
		private String endtime;
		private String attion_time;
		private int hitcount;
		private String time;
		private String user_number;
		private int departmentcode;
		private int likenum;
		private int dislikenum;
		private List<Pic> pic_url_list;
		public int getClassnotifyid() {
			return classnotifyid;
		}
 
		public void setClassnotifyid(int classnotifyid) {
			this.classnotifyid = classnotifyid;
		}
		public String getTheme() {
			return theme;
		}
		public void setTheme(String theme) {
			this.theme = theme;
		}
		public String getPlace() {
			return place;
		}
		public void setPlace(String place) {
			this.place = place;
		}
		public String getContent() {
			return content;
		}
		public void setContent(String content) {
			this.content = content;
		}
		public String getFilepath() {
			return filepath;
		}
		public void setFilepath(String filepath) {
			this.filepath = filepath;
		}
		public String getStarttime() {
			return starttime;
		}
		public void setStarttime(String starttime) {
			this.starttime = starttime;
		}
		public String getEndtime() {
			return endtime;
		}
		public void setEndtime(String endtime) {
			this.endtime = endtime;
		}
		public String getAttion_time() {
			return attion_time;
		}
		public void setAttion_time(String attion_time) {
			this.attion_time = attion_time;
		}
		public int getHitcount() {
			return hitcount;
		}
		public void setHitcount(int hitcount) {
			this.hitcount = hitcount;
		}
		public String getTime() {
			return time;
		}
		public void setTime(String time) {
			this.time = time;
		}
		
		public int getDepartmentcode() {
			return departmentcode;
		}
		public void setDepartmentcode(int departmentcode) {
			this.departmentcode = departmentcode;
		}
		public int getLikenum() {
			return likenum;
		}
		public void setLikenum(int likenum) {
			this.likenum = likenum;
		}
		
		public String getUser_number() {
			return user_number;
		}

		public void setUser_number(String user_number) {
			this.user_number = user_number;
		}

		public int getDislikenum() {
			return dislikenum;
		}
		public void setDislikenum(int dislikenum) {
			this.dislikenum = dislikenum;
		}
		public List<Pic> getPic_url_list() {
			return pic_url_list;
		}
		public void setPic_url_list(List<Pic> pic_url_list) {
			this.pic_url_list = pic_url_list;
		}
		public int getCode() {
			return code;
		}
		public void setCode(int code) {
			this.code = code;
		}
		public String getMsg() {
			return msg;
		}
		public void setMsg(String msg) {
			this.msg = msg;
		}


	}

	class Pic{
		private String pic_url;

		public String getPic_url() {
			return pic_url;
		}

		public void setPic_url(String pic_url) {
			this.pic_url = pic_url;
		}

	}

}
